<?php

function online_summy()
{
    global $curruser;
    global $conf;
    global $gametype;
    $member_max_limit = intval($conf->get("member_max_limit"));
    echo "<table>";
    $rs = getdb("select count(sid) from k_sessions where uid!=2");
    echo "<tr valign=top align=right><td>总连线数：<td>".$rs->f[0];
    if ( $member_max_limit < $rs->f[0] )
    {
        $conf->set("member_max_limit" , $rs->f[0]);
    }
    $rs = getdb("select count(sid) from k_sessions where uid is not null and uid!=2");
    echo "<tr valign=top align=right><td>会员连线数：<td>".$rs->f[0];
    $rs = getdb("select count(distinct uid) from k_sessions where uid!=2");
    echo "<tr valign=top align=right><td>会员数：<td>".$rs->f[0];
    /*if ( $curruser['account'] == G_SUPERACCOUNT && $curruser['acl'] == 255 )
    {
        $rs = getdb("select host,count(ip) as c from k_sessions where uid!=2 group by host order by c,host");
        echo "<tr valign=top align=right><td>主机连线数：<td><table width=100% border=0 cellpadding=1 cellspacing=0>";
        while ( ! $rs->eof )
        {
            echo "<tr><td>".$rs->f[0]."<td align=right width=23pt>".$rs->f[1];
            $rs->movenext();
        }
        echo "</table>";
    }*/
    $rs = getdb("select ip,count(host) as c from k_sessions where uid!=2 group by ip order by ip,c");
    echo "<tr valign=top align=right><td>Client 连线数：<td><table width=100% border=0 cellpadding=1 cellspacing=0>";
    while ( ! $rs->eof )
    {
        echo "<tr><td>".$rs->f[0]."<td align=right width=23pt>".$rs->f[1];
        $rs->movenext();
    }
    echo "</table>";
    echo "</table>";
    echo "<p><a href='?op=admin&fp=online&cmd=time&gametype={$gametype}'>全部连线</a></p>";
}

function Second2Str($sec)
{
    $mm = intval($sec / 60);
    $ss = $sec % 60;
    if ( $ss < 10 )
    {
        $ss = "0".$ss;
    }
    return $mm.":".$ss;
}

if ( ! defined("IN_OP") )
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
$gType = chkGametype($gametype);
switch ( $gType )
{
    case 0 :
        $ui = new UI();
        if ( $curruser['prev_id'] == 0 )
        {
            include( "admin_menu.php" );
        }
        else
        {
            include( "admin_menu1.php" );
        }
        break;
    default :
        include_once( "class_3d/CheckMode_3d.php" );
        $chk = new CheckMode_3d($curruser['acl'] , 1 , $gametype);
        $chk->checkShow3dPage();
        unset($chk);
        $ui = new UI_3D();
        $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>".( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" );
        $ui->set("jslink" , $jslink);
        $ui->header();
        if ( $curruser['prev_id'] == 0 )
        {
            include( "admin_menu_3d.php" );
        }
        else
        {
            include( "admin_menu1_3d.php" );
        }
        break;
}
$conf = new Config();
$page = getvar("page");
if ( $page == "" )
{
    $page = 1;
}
$begin = 30 * ( $page - 1 );
$sql = "select * from k_sessions where uid!=2 order by ";
$cmd = getvar("cmd");
if ( $cmd == "" )
{
    $cmd = "summy";
}
switch ( $cmd )
{
    case "check" :
        sess_gc();
        redirect("?op=admin&fp=online&gametype={$gametype}");
        exit();
    case "summy" :
        sess_gc();
        online_summy();
        exit();
        break;
    case "account" :
        $sql .= "uid";
        break;
    case "host" :
        $sql .= "host";
        break;
    case "ip" :
        $sql .= "ip";
        break;
    case "proxy" :
        $sql .= "proxy";
        break;
    default :
        $sql .= "createtime";
        break;
}
$rs = getdb($sql);
$tmp = "";
$i = $begin + 1;
include_once( "ip/ip_fun.php" );
$ipfun=new QQWry();
while ( ! $rs->eof )
{
    if ( 0 < $rs->f['uid'] )
    {
        $info = get_user($rs->f['uid']);
        $tmp .= "<tr class=td2>";
        $tmp .= "<td align=right nowrap>".$i ++;
        $tmp .= "<td nowrap align=right>".$info['acl'];
        $tmp .= "<td nowrap>".$info['account'];
        $tmp .= "<td nowrap>".$info['name']."</td>";
        $tmp .= "<td>".date("H:i:s" , $rs->f['createtime']);
        $tmp .= "<td>".date("H:i:s" , $rs->f['lastupdate']);
        $tmp .= "<td align=right>".Second2Str(systime() - $rs->f['createtime']);
		$ipfun->QQWry($rs->f['ip']); 
		$area=$ipfun->Country;
        $tmp .= "<td>".$rs->f['ip']."({$area})";
    }
    $rs->movenext();
}
$tpl = new Template2();
$tpl->set("host" , G_SITENAME);
$tpl->set("list" , $tmp);
$tpl->set("gametype" , $gametype);
$tpl->load("online" , "online.htm");
$tpl->show("online");
?>